package org.whh.auth.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.whh.auth.domain.Role;
import org.whh.auth.mapper.RoleMapper;
import org.whh.auth.service.IRoleService;
import org.whh.base.service.impl.BaseServiceImpl;
import org.whh.dto.result.MenuDTO;
import org.whh.dto.result.PermissionDTO;

import java.util.List;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class RoleServiceImpl extends BaseServiceImpl<Role> implements IRoleService {
    @Autowired
    RoleMapper roleMapper;

    @Override
    public void setRolePermisison(PermissionDTO dto) {
        roleMapper.deleteRolePermissionByRoleId(dto.getRoleId());

        roleMapper.saveRolePermission(dto.getRoleId(),dto.getPermissionSns());
    }

    @Override
    public List<String> getSnByRowId(Long roleId) {
        return roleMapper.getSnByRowId(roleId);
    }

    @Override
    public void setRoleMenu(MenuDTO dto) {
        roleMapper.deleteRoleMenuByRoleId(dto.getRoleId());
        roleMapper.saveRoleMenu(dto.getRoleId(),dto.getMenuIds());
    }

    @Override
    public List<Long> getMenuIdByRowId(Long roleId) {
        return roleMapper.getMenuIdByRowId(roleId);
    }

    @Override
    public List<Long> getAllRoleId() {
        List<Long> list=roleMapper.getAllRoleId();
        return list;
    }

    @Override
    public List<Role> getRoles() {
        return roleMapper.getRoles();
    }
}
